
public class CheckOrder {

	/**
	 * @param args
	 */
	public static void main(String[] args)
	{
		int [] myArray1 = {5,54,4,9,7,8,4,2,12,5}; //create an array for testing
		System.out.println("the value for myArray1 before sorting is 	"); 
		
		printout(myArray1);  //this function print an array before re-ordered
		
		sort(myArray1); //all the re-ordering processes are in here
		
		System.out.println("the value for myArray1 after sorting is 	"); 
		printout(myArray1); //this function print an array after re-ordered

	}
	
	static void sort(int []  array_input)
	{
		for(int counter = 0;counter<10;counter++) //this means repeat "incorrect order checking" process for 10 times
		{
			for (int i = 0;i< array_input.length -1 ;i++) // go through all array and detect incorrect order
			{
				if (array_input[i]>array_input[i+1])
				{
				swap(array_input,i,i+1); //if, incorrectly ordered, then swap
				}
			}
		}
	}
	
	static  void printout(int [] input) // this is the function for printing array
	{
		for (int i = 0;i<input.length;i++)
			System.out.print(input[i]+"  ");

		System.out.println();
		System.out.println();
	}
	static void swap(int[] array, int index1, int index2)
	//swaps the items at location array[index1] and array[index2]
	{
		int temp = array[index1];
		array[index1]=array[index2];
		array[index2]=temp;
	}
	

}
